 
import { reqUserAddressList,reqGetTradeListData } from "@/api";

const state = {
  userAddressList:[],
  tradeInfo:{}
}
const actions = {
  // 获取用户的收获地址
  async getUserAddressList({commit}) {
    const result = await reqUserAddressList()
    if (result.code === 200) {
      commit('SAVE_USER_ADDRESS_LIST',result.data)
    } else {
      console.log(result.message);
    }
  },
  //  获取trade页面中的数据
  async getTradeInfoData({commit}) {
    const result = await reqGetTradeListData()
    if (result.code === 200) {
      commit('SAVE_TRADE_INFO_DATA',result.data)
    } else {
      console.log(result.message)
    }
  }
}
const mutations = {
  SAVE_USER_ADDRESS_LIST(state,addressList) {
    state.userAddressList = addressList
  },
  SAVE_TRADE_INFO_DATA(state,tradeInfo) {
    state.tradeInfo = tradeInfo
  }
}
const getters = {
   // 商品列表
   detailArrayList(state) {
    return state.tradeInfo.detailArrayList
  },
  // 商品总金额
  originalTotalAmount() {
    return state.tradeInfo.originalTotalAmount
  },
  // 实付金额
  totalAmount() {
    return state.tradeInfo.totalAmount
  },
  // 商品数量
  totalNum() {
    return state.tradeInfo.totalNum
  },
  // 订单编号
  tradeNo() {
    return state.tradeInfo.tradeNo
  }
}
export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters
}